<?php
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'main';
cfc('core')->checklogin();
set_html('title','我的订单');
if($_RQ['op']=='main'){
	$return['setting']=$this->plugin_setting('page');
	$params=array('merchid'=>$_SESSION['onemerchid'],'uniacid'=>$_SESSION['uniacid']);
    $orderby='level asc';
	$total='';
	$levels=$this->getall('level',$params,array(),'',$orderby);
	foreach($levels as &$item){
		$params=array('merchid'=>$_SESSION['onemerchid'],'mid'=>$_SESSION['uid'],'level'=>$item['id']);
		if(isset($_RQ['type'])){
			$params['type']=$_RQ['type']!=0?$_RQ['type']:array(0,3);
		}
		$item['num']=$this->count('commission',$params);
	}
	$return['levels']=$levels;
	$return['params']=array(
		'level'=>$levels['id'],
		'page'=>1,
	);
	$return['unit']='元';
	$params=array('merchid'=>$_SESSION['onemerchid'],'uniacid'=>$_SESSION['uniacid'],'mid'=>$_SESSION['uid']);
	if(isset($_RQ['type'])){
		$params['type']=$_RQ['type']!=0?$_RQ['type']:array(0,3);
		$return['params']['type']=$_RQ['type'];
		if($_RQ['type']==6){
			$return['unit']='分';
		}elseif($_RQ['type']==7){
			$return['unit']='个';
		}
	}
	$return['commission_money']=$this->sum('commission',$params,'money');
	$return['commission_total']=$this->count('commission',$params);
	$return['list']=array();
	$return['psize']=20;
	exi($return);
}
if($_RQ['op']=='list'){
	$params=array('merchid'=>$_SESSION['onemerchid'],'mid'=>$_SESSION['uid']);
	$level=intval($_RQ['level']);
	if(!$level){
		$level=1;
	}
	//$params['level']=$level;
	if(isset($_RQ['type'])){
		$params['type']=$_RQ['type']!=0?$_RQ['type']:array(0,3);
		$return['params']['type']=$_RQ['type'];
		//$params['type']=$_RQ['type'];
	}
	$psize=20;
	$pindex=intval($_RQ['page'])?:1;
	$parameter=array(
		'params'=>$params,
		'limit'=>array($pindex,$psize),
		'orderby'=>'id desc',
	);
	$list=$this->get_list('commission',$parameter);
	if(!$list){
		exi('none');
	}
	foreach($list as &$item){
		$order=pdo_get('jy_weishop_order',array('uniacid'=>$_SESSION['uniacid'],'ordersn'=>$item['ordersn']));
		$item['member']=model('core/member')->basic($order['mid']);
		$item['goodsid']=pdo_getcolumn('jy_weishop_order_goods',array('orderid'=>$order['id']),'goodsid');
		$item['goodstitle']=pdo_getcolumn('jy_weishop_goods',array('id'=>$item['goodsid']),'title');
		$item['statustitle']=$this->commission_status[$item['status']];
		$item['createtime']=date('Y-m-d H:i:s',$item['createtime']);
		if($item['type']==2 && $item['status']==0){
			$this->update('commission',array('status'=>1),array('id'=>$item['id']));
		}
		if($item['type']==6){
			$item['unit']='分';
		}elseif($item['type']==7){
			$item['unit']='个';
		}else{
			$item['unit']='元';
		}
		$item['type']=$this->fee_types[$item['type']];
	}
	//exi('num'.count($list),'error');
	exi($list);
}
?>